<template>
    <div class="pasenges">
      <div class="part-top">
          <div class="user-info-section">
            <div class="img-div">
                <img class="head-icon" :src="icon"/>
            </div>
            <div class="user-info">
              <p class="name">{{!realname?username:realname}}</p>
              <div class="job-container"><span class="job">{{roleName}}</span></div>
            </div>
            <div class="div-balance">
              <span class="iconfont icon-yue"></span>
              <span class="word">账户余额：</span>
              <span class="balance">&yen;<span>{{balance}}</span></span>
            </div>
          </div>

          <!-- 功能模块 -->
          <div class="function-section">
            <ul>
              <li v-for="(item,index) in serviceArr" @click="cellClickHandle(item,$event)" :key="index" @touchstart="onCellDown" @touchcancel="onCellUp" @touchend="onCellUp" :class="[{'notLast':index!=serviceArr.length-1}]">
                <div class="cell-wapper">
                  <span :class="'iconfont '+item.icon"></span>
                  <div class="icon-name">{{item.names}}</div>
                </div>
              </li>
            </ul>
          </div>
      </div>
      <!-- <div class="part-bottom">
      </div> -->
    </div>  
</template>
<script>
import meConfig from "./meConfig";
import wxpay from "../../common//js/wxpay";
import { mapState } from "vuex";
import Vue from "vue";
import wxqrcode from "../../common/js/wxqrcode";
import { Toast, Button } from "mint-ui";
import "mint-ui/lib/button/style.css";
import "mint-ui/lib/toast/style.css";
Vue.component(Button.name, Button);
Vue.component(Toast.name, Toast);

export default {
  name: "v-me",
  data() {
    return {
      roleName: "",
      resultObj: {},
      serviceArr: null
    };
  },
  components: {},
  mounted() {
    this.wxReady();
    this.initFunction();
  },
  activated() {},
  methods: {
    initFunction() {
      let configItem = meConfig[this.role.toString()];
      this.roleName = configItem.roleName;
      this.serviceArr = configItem.service;
    },
    wxReady() {
      // wxqrcode.getWxData(this);
    },
    onCellUp(e) {
      let cell = e.currentTarget;
      cell.style.backgroundColor = "transparent";
    },
    onCellDown(e) {
      let cell = e.currentTarget;
      cell.style.backgroundColor = "#f8f8f8";
    },
    QrCodeEnd(results) {
      this.resultObj = JSON.parse(results);
      if (!this.resultObj.consumeid) return;
      this.requestUseGood();
    },
    requestUseGood() {
      this.$store.dispatch("toggleLoading", true);

      this.$http
        .post(this.path + `store/Goods/useCoupon`, {
          cuid: this.resultObj.consumeid,
          userid: this.resultObj.userid,
          buyid: this.resultObj.buyid,
          uid:this.userid
        })
        .then(response => {
          let data = response.body;
          if (data.status == "ok") {
            this.scanGoodSuccessHandle();
          } else {
            Toast({
              message: data.msg,
              iconClass: "iconfont icon-tishi1",
              duration: 2000
            });
          }
          this.$store.dispatch("toggleLoading", false);
        })
        .catch(response => {
          //请求出错处理
          console.log(response);
        });
    },
    scanGoodSuccessHandle() {
      Toast({
        message: "操作成功",
        iconClass: "iconfont icon-msnui-success",
        duration: 2000
      });
    },
    cellClickHandle(cellData, event) {
      ////this.onScanQr(event);
      //this.QrCodeEnd("fuc:integral,userid:21,id:5aa3e888ab21c");
      //this.QrCodeEnd("");//
      if (cellData.names == "扫一扫") this.onScanQr(event);
      else if (cellData.names == "联系我们")
        window.location.href = "tel:" + this.serviceTel;
      else this.$router.push({ name: cellData.tourl });
    },
    onScanQr(event) {
      // this.QrCodeEnd("fuc:good,userid:1,id:2");
      wxqrcode.wxscanQRCode(this);
    }
  },
  computed: {
    ...mapState([
      "openid",
      "path",
      "userid",
      "role",
      "username",
      "realname",
      "icon",
      "phoneno",
      "serviceTel",
      "balance"
    ])
  }
};
</script>

<style lang="stylus" rel="stylesheet/stylus" scoped>
@import '../../common/css/mixin.styl';

.pasenges {
  width: 100%;
  min-height: 100%;
  // display: flex;
  // flex-direction: column;
  // justify-content: space-between;
  background-color: #f1f1f1;
  padding-bottom: 0.2rem;
  box-sizing: border-box;

  .part-top {
    overflow: hidden;
    width: 100%;
    margin-bottom: 0.2rem;

    .user-info-section {
      width: 100%;
      background: url('../../assets/bg_1.png');
      background-repeat: no-repeat;
      background-size: 100% auto;
      background-color: #fff;
      padding-top: 0.52rem;
      padding-bottom: 0.18rem;

      .img-div {
        font-size: 0;
        margin-left: 0.18rem;

        .head-icon {
          border-radius: 50%;
          width: 0.7rem;
          height: 0.7rem;
          box-shadow: 0 1px 6px rgb(244, 187, 216);
        }
      }

      .user-info {
        margin-left: 0.2rem;
        margin-top: 0.2rem;
        display: flex;
        align-items: center;

        .name {
          color: #2a2a2a;
          font-size: 0.17rem;
        }

        .job-container {
          margin-left: 0.1rem;
          background-color: #ff84bb;
          border-radius: 0.04rem;
          padding: 0.03rem 0.09rem 0.02rem 0.1rem;

          .job {
            color: #fff;
            font-size: 0.12rem;
            letter-spacing: 0.02rem;
          }
        }
      }

      .div-balance {
        margin-left: 0.18rem;
        margin-top: 0.09rem;

        // display: flex;
        // align-items: center;
        .icon-yue {
          color: #ff84bb;
          font-size: 0.2rem;
          // position relative;
          // top: 0.01rem;
        }

        .word {
          margin-left: 0.02rem;
          color: #303030;
          font-size: 0.12rem;
          letter-spacing: 0.01rem;
        }

        .balance {
          color: #ff84bb;
          font-size: 0.12rem;

          span {
            font-size: 0.16rem;
            margin-left: 0.03rem;
          }
        }
      }
    }

    .function-section {
      margin: 0.1rem 0.1rem 0 0.1rem;
      padding: 0.12rem 0.06rem;
      box-sizing: border-box;
      // box-shadow: 0 0 2px rgba(150, 150, 150, 0.4);
      border-radius: 0.08rem;
      background-color: #fff;

      ul {
        width: 100%;
        display: flex;
        flex-wrap: wrap;
        align-items: center;

        li {
          width: 33%;
          min-height: 0.7rem;
          text-align: center;
          display: flex;
          align-items: center;
          justify-content: center;
          border-radius: 0.04rem;

          // &.notLast {
          // border-bottom-1px(#f1f1f1);
          // }
          .cell-wapper {
            .iconfont {
              font-size: 0.28rem;
              color: #ff84bb;
            }

            .icon-name {
              margin-top: 0.08rem;
              font-size: 0.12rem;
              letter-spacing: 0.01rem;
            }
          }
        }
      }
    }
  }
}
</style>
